function TableOperator(){
	var ap = new AjaxOperator();
	
	this.createTable = function(table, data){
		table.empty();
		table.append($("<caption>").text("User List"));
        var thead=$("<thead>").append($("<tr>")
                                          .append($("<th>").text("Id"))
                                          .append($("<th>").text("Name"))
                                          .append($("<th>").text("Sex"))
                                          .append($("<th>").text("Salary"))
                                          .append($("<th>").text("Birth")));
        table.append(thead);
        data.forEach((item)=>{
        	var date = new Date(item.birth);
        	var birth = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
        	var td1=$("<td>").text(item.id);
            var td2=$("<td>").text(item.name);
            if(item.sex==true){
            	var td3=$("<td>").text("Male");
            }else{
            	var td3=$("<td>").text("Female");
            }
            
            var td4=$("<td>").text(item.sal);
            var td5=$("<td>").text(birth);
            var td6=$("<td>").append($("<button>").text("Delete").attr("uid",item.id)
            				.addClass("btn").addClass("btn-danger").addClass("delete"));
            var td7=$("<td>").append($("<button>").text("Update")
            				.attr("uid",item.id).attr("name", item.name).attr("sex", item.sex).attr("sal", item.sal).attr("birth",item.birth)
            				.addClass("btn").addClass("btn-warning").addClass("update")
            				.attr("data-toggle","modal")
            				.attr("data-target","#myModal"));
            var tr=$("<tr>").append(td1).append(td2).append(td3).append(td4).append(td5).append(td6).append(td7);
            table.append(tr);
        });
	}
	
	this.addTableRow = function(table, data){
		var date=new Date(data.birth);
		var birth=date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
		var td1=$("<td>").text(data.id);
        var td2=$("<td>").text(data.name);
        if(data.sex==true){
        	var td3=$("<td>").text("Male");
        }else{
        	var td3=$("<td>").text("Female");
        }
        
        var td4=$("<td>").text(data.sal);
        var td5=$("<td>").text(birth);
        var td6=$("<td>").append($("<button>").text("Delete").attr("uid",data.id)
        				.addClass("btn").addClass("btn-danger").addClass("delete"));
        var td7=$("<td>").append($("<button>").text("Update")
        				.attr("uid",data.id).attr("name", data.name).attr("sex", data.sex).attr("sal", data.sal).attr("birth",data.birth)
        				.addClass("btn").addClass("btn-warning").addClass("update")
        				.attr("data-toggle","modal")
        				.attr("data-target","#myModal"));
        var tr=$("<tr>").append(td1).append(td2).append(td3).append(td4).append(td5).append(td6).append(td7);
        table.append(tr);
        this.bindUpdateEvent();
	}
	
	this.bindDelEvent = function(url, fndone, fnfail){
		$(".delete").on("click", function(){
			var uid = $(this).attr("uid");
			ap.sendGet(url+"?uid="+uid, fndone, fnfail);
		});
	}
	
	this.bindUpdateEvent = function(){
		$(".update").on("click", function(){
			var uid = $(this).attr("uid");
			var name = $(this).attr("name");
			var sex = $(this).attr("sex");
			var sal = $(this).attr("sal");
			var birth = $(this).attr("birth");
			$("#modal_id").val(uid);
			$("#modal_name").val(name);
			if(sex=="true"){
				$("#modal_sexm").attr("checked",true);
				$("#modal_sexf").attr("checked",false);
			}else{
				$("#modal_sexm").attr("checked",false);
				$("#modal_sexf").attr("checked",true);
			}
			$("#modal_sal").val(sal);
			$("#modal_birth").val(birth);
		});
	}
}